home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-11-08 | 9.2 KB | 315 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: FWBitmap.h
- // Release Version: $ 1.0d11 $
- //
- // Copyright: © 1995 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #ifndef FWBITMAP_H
- #define FWBITMAP_H
-
- #ifndef FWGROBJ_H
- #include "FWGrObj.h"
- #endif
-
- #ifndef FWGCONST_H
- #include "FWGConst.h"
- #endif
-
- #ifndef FWRECT_H
- #include "FWRect.h"
- #endif
-
- #ifndef FWGRDEF_H
- #include "FWGrDef.h"
- #endif
-
- #ifndef FWRESOUR_H
- #include "FWResour.h"
- #endif
-
- #ifndef FWGC_H
- #include "FWGC.h"
- #endif
-
- #ifndef FWPALETE_H
- #include "FWPalete.h"
- #endif
-
- #if FW_LIB_EXPORT_PRAGMAS
- #pragma lib_export on
- #endif
-
- const FW_PlatformError FW_xGraphicException = -30020; // !!!JEL need offical value!!!
- const FW_PlatformError FW_xInvalidBitmapData = -30021;
-
- //========================================================================================
- // Forward Class Declarations
- //========================================================================================
-
- class FW_CLASS_ATTR FW_CBitmapRep;
- class FW_CLASS_ATTR FW_CWritableStream;
- class FW_CLASS_ATTR FW_PPicture;
- class FW_CLASS_ATTR FW_CGraphicContext;
- class FW_CLASS_ATTR FW_CColor;
-
- //========================================================================================
- // class FW_PBitmap
- //========================================================================================
-
- class FW_CLASS_ATTR FW_PBitmap : public FW_CGraphicCountedPtr
- {
- public:
- FW_DECLARE_CLASS
-
- public:
- FW_PBitmap();
- virtual ~FW_PBitmap();
-
- FW_PBitmap(short width, short height, short pixelSize, FW_Palette palette = NULL);
- FW_PBitmap(void* image, unsigned long imageSize, short width, short height, short pixelSize, FW_Palette palette = NULL);
-
- #ifdef FW_BUILD_MAC
- static const FW_CRect gWholePicture;
- FW_PBitmap(FW_PPicture picture,
- const FW_CColor& fillColor = FW_kRGBWhite,
- const FW_CRect& pictPart = gWholePicture); // From a picture
- #endif
-
- FW_PBitmap(FW_CResourceFile& resourceFile, FW_ResourceId resId); // From a Resource
-
- FW_PBitmap(FW_PlatformBitmap platformBitmap); // Set fOwnBitmap to FALSE
-
- FW_PBitmap(const FW_PBitmap& other);
-
- FW_PBitmap& operator=(const FW_PBitmap& other);
-
- FW_CBitmapRep* operator->();
- const FW_CBitmapRep* operator->() const;
- };
-
- //========================================================================================
- // class FW_CBitmapRep
- //========================================================================================
-
- class FW_CLASS_ATTR FW_CBitmapRep : public FW_CGraphicCountedPtrRep
- {
- friend class FW_CLASS_ATTR FW_PBitmap;
-
- public:
- FW_DECLARE_CLASS
-
- //----------------------------------------------------------------------------------------
- // Constructors/Destructors
- //
- private:
- FW_CBitmapRep(short width, short height, short pixelSize, FW_Palette palette);
- FW_CBitmapRep(void* image, unsigned long imageSize, short width, short height, short pixelSize, FW_Palette palette);
-
- #ifdef FW_BUILD_MAC
- FW_CBitmapRep(FW_PPicture picture, const FW_CColor& fillColor, const FW_CRect& pictPart);
- #endif
-
- FW_CBitmapRep(FW_PlatformBitmap platformBitmap);
- FW_CBitmapRep(FW_CResourceFile& resourceFile, FW_ResourceId resId);
-
- FW_CBitmapRep(FW_CReadableStream& archive, FW_Boolean dibFileHeader = TRUE);
-
- virtual ~FW_CBitmapRep();
-
- //----------------------------------------------------------------------------------------
- // Inherited API
- //
- public:
- virtual void Flatten(FW_CWritableStream& archive) const;
- virtual FW_Boolean IsEqual(const FW_CGraphicCountedPtrRep* other) const;
-
- //----------------------------------------------------------------------------------------
- // New API
- //
- public:
- // ----- Copying -----
- FW_PBitmap Copy() const;
- FW_PBitmap Copy(const FW_CRect& srcRect) const;
-
- // ----- Get, Set, Adopt and Orphan
- FW_PlatformBitmap GetPlatformBitmap() const; // return fPlatformBitmap
- FW_Boolean IsPlatformBitmapOrphan() const;
- FW_PlatformBitmap OrphanPlatformBitmap(); // return fPlatformBitmap, and change ownership
-
- void SetPlatformBitmap(FW_PlatformBitmap newBitmap); // Set a new platform Bitmap (fOwnBitmap = FALSE)
- void AdoptPlatformBitmap(FW_PlatformBitmap newBitmap); // Adopt a new platform Bitmap (fOwnBitmap = TRUE)
-
- // ----- Palette -----
-
- FW_Palette GetPalette() const;
- void SetPalette(FW_Palette palette);
- // Bitmap always owns its palette
-
- // ----- Archiving -----
- static void* Read(FW_CReadableStream& archive);
-
- // ---- Geometry -----
- void GetBitmapInfo(short& width, short& height,
- short& rowBytes, short& pixelSize) const; // Size in pixels
-
- void GetBitmapBounds(FW_CRect& bounds) const; // Size in pixels
- void GetBitmapBounds(FW_CGraphicContext& gc, FW_CRect& bounds) const; // Size in gc units
-
-
- enum // Options for ChangeBitmap
- {
- kChangeBitmap_Crop,
- kChangeBitmap_Scale
- };
-
- void ChangeBitmap(void* image, short imageSize,
- short width, short height,
- short pixelSize,
- short howToChangeSize);
-
- // ----- Copy Pixels -----
- void CopyPixels(FW_PBitmap dstBitmap,
- const FW_CRect& srcRect,
- const FW_CRect& dstRect) const;
-
- #ifdef FW_BUILD_MAC
- // ----- Conversion -----
- FW_PPicture GetAsPicture();
- FW_PPicture GetAsPicture(const FW_CRect& srcRect);
- #endif
-
- // ----- Mac Lock/Unlock -----
- #ifdef FW_BUILD_MAC
- PixMapHandle MacLockPixels();
- void MacUnlockPixels();
- FW_Boolean MacIsPixelsLocked() const;
- #endif
-
- protected:
- void MakePlatformBitmap(short width, short height, short pixelSize, FW_Palette palette);
- void DisposePlatformBitmap();
- void SetImage(void* image, unsigned long imageSize);
-
- // ----- Reading and writing -----
- public:
- void WriteToPlatformFormat(const FW_CWritableStream& stream, FW_Boolean dibFileHeader) const;
-
- private:
- void ReadFromPlatformFormat(const FW_CReadableStream& stream, FW_Boolean dibFileHeader);
-
- //----------------------------------------------------------------------------------------
- // Data Members
- //
- private:
- FW_Boolean fOwnBitmap;
- FW_PlatformBitmap fPlatformBitmap;
-
- #ifdef FW_BUILD_MAC
- short fLockCount;
- PixMapHandle fPixMapHandle;
- #endif
- #ifdef FW_BUILD_WIN
- // Windows GDI can only work with DDBs of two color depths: monochrome and whatever the
- // current display setting is. But the user can ask for an aribtrary color depth!
- // To solve this, I have to remember the requested color depth and use what GDI can do
- short fUserColorDepth;
- FW_Palette fWinPalette;
- #endif
- };
-
- //========================================================================================
- // class FW_CBitmapContext
- //========================================================================================
-
- class FW_CLASS_ATTR FW_CBitmapContext : public FW_CGraphicContext
- {
- public:
- FW_CBitmapContext(Environment* ev, FW_PBitmap& bitmap);
- virtual ~FW_CBitmapContext();
-
- private:
- FW_PBitmap fBitmap;
- FW_CGraphicDevice* fGraphicDevice;
-
- #ifdef FW_BUILD_WIN
- HBITMAP fOldBitmap;
- #endif
- };
-
- //========================================================================================
- // Inlines
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // FW_PBitmap::operator->
- //----------------------------------------------------------------------------------------
- inline FW_CBitmapRep* FW_PBitmap::operator->()
- {
- return (FW_CBitmapRep*) GetRep();
- }
-
-
- //----------------------------------------------------------------------------------------
- // FW_PBitmap::operator->
- //----------------------------------------------------------------------------------------
- inline const FW_CBitmapRep* FW_PBitmap::operator->() const
- {
- return (const FW_CBitmapRep*) GetRep();
- }
-
- #ifdef FW_BUILD_MAC
- //----------------------------------------------------------------------------------------
- // FW_CBitmapRep::MacIsPixelsLocked
- //----------------------------------------------------------------------------------------
- inline FW_Boolean FW_CBitmapRep::MacIsPixelsLocked() const
- {
- return fLockCount != 0;
- }
- #endif
-
- //----------------------------------------------------------------------------------------
- // FW_CBitmapRep::GetPlatformBitmap
- //----------------------------------------------------------------------------------------
- inline FW_PlatformBitmap FW_CBitmapRep::GetPlatformBitmap() const
- {
- return fPlatformBitmap;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CBitmapRep::IsPlatformPictOrphan
- //----------------------------------------------------------------------------------------
- inline FW_Boolean FW_CBitmapRep::IsPlatformBitmapOrphan() const
- {
- return !fOwnBitmap;
- }
-
- #ifdef FW_BUILD_MAC
-
- //========================================================================================
- // CLASS FW_CMacPixelLock
- //========================================================================================
-
- class FW_CMacPixelLock FW_AUTO_DESTRUCT_OBJECT
- {
- public:
- FW_CMacPixelLock(FW_CBitmapRep* bitmapRep);
- virtual ~FW_CMacPixelLock();
-
- PixMapHandle GetPixMapHandle() const;
-
- private:
- FW_CBitmapRep* fBitmapRep;
- PixMapHandle fPixMapHandle;
- };
-
- #endif
-
- #if FW_LIB_EXPORT_PRAGMAS
- #pragma lib_export off
- #endif
-
- #endif
-